from GBDTModel import GBDTModel
import seaborn as sns
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from pandas import DataFrame

sns.set()


# 处理新数据
def main():
    dataset = pd.read_excel('../data/newData.xlsx')
    # 要分析的数据
    X = dataset.iloc[5:, 1:360].values
    print(X[345+1:,0],X[345-1:,0].shape)
    # X = [[row[i] for row in X] for i in range(len(X[0]))]
    print("======原始数据的形状========")
    print(np.array(X).shape)
    print(X)
    # 原始机测、手测数据
    mmv = pd.read_excel('../excelData/machine_manual_values.xlsx')
    print("======原始机测、手测数据的形状========")
    print(np.array(mmv).shape)
    # print(mmv)
    second_manual_value = mmv.iloc[3, 1:28].values
    print(second_manual_value)
    print(np.array(second_manual_value).shape)
    k_second = []
    for i in second_manual_value:
        tmp = (i - 0.6) / 0.05
        k_second.append(360 - int(tmp))
    print(k_second)
    print(np.array(k_second).shape)

    # 第三层
    # for i in range(len(X[0])):
    x=np.array([1,2,3])
    # print(np.average(x))
    # print(np.var(x))
    print("分层")
    # 方差-均值
    avg_var_form=[[],[]]
    print(np.array(avg_var_form).shape)
    print(avg_var_form)

    for i in range(108):
        ch = (int)(i / 4)
        k_value = k_second[ch]
        # print(k_value)
        four_layer = X[k_value:360,i]
        # print(four_layer)
        avg=avgue(four_layer)
        # print(avg)
        var=np.var(four_layer)
        # print(var)
        avg_var_form[0].append(avg)
        avg_var_form[1].append(var)
    print("avg_var_form")
    print(np.array(avg_var_form).shape)
    print(avg_var_form)
    df = DataFrame(avg_var_form)
    df.to_excel('../excelData/avg_var_form.xlsx')


def avgue(x):
    length=len(x)
    sum=0
    for i in range(length):
        sum=sum+x[i]
    return sum/length

name = "../data/GBDT"
num_of_index = 1
if __name__ == "__main__":
    main()
